package com.huage_07.lesson_07;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;

public class PropertiesIO {
    public static void main(String[] args) throws IOException{
        myStore();

//        myLoad();
    }

    private static void myLoad() throws IOException{
        FileReader fr = new FileReader("class1\\src\\com\\huage_07\\lesson_07\\Properties.txt");

        Properties prop = new Properties();
        prop.load(fr);

        Set<String> keys = prop.stringPropertyNames();
//        System.out.println( keys);
        for (String key : keys){
            System.out.println(key+","+prop.getProperty(key));
        }

        fr.close();
    }

    private static void myStore() throws IOException {
        Properties prop = new Properties();

        prop.setProperty("张三","23");
        prop.setProperty("李四","24");
        prop.setProperty("王五","25");

        FileWriter fw = new FileWriter("class1\\src\\com\\huage_07\\lesson_07\\Properties.txt");
//        FileWriter fw = new FileWriter("class1\\src\\com\\huage_07\\lesson_07\\Game.txt");
        prop.store(fw,"Properties练习");


        fw.close();
    }
}
